

//   全选

function selectAll(){
    $("input[type='checkbox']").each( function() {
        if($(this).prop("checked")==true) {
            $("input[type='checkbox']").prop('checked', true);
            return;

        } else {
            $("input[type='checkbox']").prop('checked', false);
            return;
        }
    });
}




$(function(){
    var username = '';
    var con_max =0;
    var money =0;

    //   批量续费
    $('#batch-account-renew').click(function(){
        batchRenewMoney();
    });


    //  时间
    $('#batch-renew-date').bind('input onchange', function() {
        var batch_date = $(this).val();
        if(batch_date <=0)
        {
            $(this).val(0);
        }
        batchRenewMoney();
    });

    //  优惠
    $('#batch-renew-type').bind('input onchange', function() {
        batchRenewMoney();
    });


    function batchRenewMoney(){


        var batch_renew_date = parseInt($('#batch-renew-date').val());

        var batch_connect_num = parseInt($('#batch-connect-num').val());


        if($("input[name='check-box']:checked").length > 0)
        {

            $('#batch-account-renew').attr('data-target','#batch-renew-account-show');
            $("input[name='check-box']:checked").each( function() {

                if(level == 2)  //  超级用户
                {
                    if($("input[name='check-box']:checked").length == 1)
                    {
                        username = $(this).parent().next().next().text();
                        con_max = parseInt($(this).parent().next().next().next().next().text())*1;
                        //money = batch_renew_date*batch_connect_num*$(this).parent().last.
                    }else{
                        username = $(this).parent().next().next().text()+','+username
                        con_max = parseInt($(this).parent().next().next().next().next().text())*1+con_max*1;
                        money = batch_renew_date*batch_connect_num
                    }



                }else{

                    if($("input[name='check-box']:checked").length == 1)
                    {
                        username = $(this).parent().next().text();
                        con_max = parseInt($(this).parent().next().next().next().text())*1;
                        money = batch_renew_date*batch_connect_num;
                        alert($(this).parent().prev().prev().prev().text());
                    }else{
                        username = $(this).parent().next().text()+','+username;
                        con_max = parseInt($(this).parent().next().next().next().text())*1+con_max*1;
                        money = batch_renew_date*batch_connect_num
                    }
                }

            });

            $('#batch-connect-num').val(con_max);
            $('#batch-username').val($.trim(username,','));

            batchRenewMoney();
            con_max='';
        }else{
            $('#batch-renew-account').attr('data-target','');
            alert("你还没选中什么！");
        }




        var batch_discount = $('#batch-renew-type option:selected').val();

        if($('#batch-renew-date').val() =="")
        {
            $('.batch-price').text('0.00');
            $('#batch-renew-price').val(0)

        } else{

            $('.batch-price').text((batch_renew_date*batch_connect_num*batch_discount));
            $('#batch-renew-price').val((batch_renew_date*batch_connect_num*batch_discount));
            $('#batch-renew-date-type').val($("#batch-renew-type").find("option:selected").text());
        }

    }


//    //   批量删除

    $('#batch-account-delete').click(function(){
        var id='';
        if($("input[name='check-box']:checked").length > 0)
        {

            $("input[name='check-box']:checked").each( function() {

                id = $(this).parent().prev().text()+','+id;
            });

            if(confirm('真的删除这些账号,删除以后该账号信息将不存在,请谨慎操作')) {
                $.ajax({
                    url: '/delete/account',          //  删除账号
                    type: 'get',
                    data: {
                        id: id
                    },
                    timeout: 5000,
                    dataType: 'json',
                    success: function (data, textStatus, jqXHR) {
                        if (data.error_code == 0) {
                            if (data.data == 'SUCCESS') {

                                $("input[name='check-box']:checked").each( function() {

                                    $(this).parent().parent().remove();

                                });
                                alert('删除成功');
                            }
                        } else {
                            alert(data.error_message);
                        }
                    }
                })

            }


        }else{
            alert("你还没选中什么！");
        }
    });
//
//
//
//
//
//
//
//
//
//
//
});